package com.example.demo.customer;

import com.example.demo.exception.NotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;

import javax.persistence.Id;
import java.util.List;

@Component
@Primary
public class CustomerService {
    private final CustomerRespository customerRespository;
    @Autowired
    public CustomerService(CustomerRespository customerRespository){
        this.customerRespository = customerRespository;
    }
    List<Customer> getCustomers(){

        return customerRespository.findAll();
    }
    Customer getCustomer(Long id){
        return customerRespository
                .findById(id)
                .orElseThrow(()-> new NotFoundException("customer"+ id+ "无法找到"));

    }
}

